/*
 * window vendor image info from 14443A card
 */

#ifndef WINDOW_VENDOR_H
#define WINDOW_VENDOR_H

#include "gkt_types.h"
#include "gkt_rfid.h"


#ifdef __cplusplus
extern "C" {
#endif

#if defined(GKT_CONFIG_SCREEN_ENABLE) && GKT_CONFIG_SCREEN_ENABLE \
	&& defined(GKT_CONFIG_WINDOW_VENDOR_IMAGE_ENABLE) \
	&& GKT_CONFIG_WINDOW_VENDOR_IMAGE_ENABLE

#include "gkt_screen.h"

#define WINDOW_VENDOR_IMAGE_ENABLE	1

#ifdef GKT_CONFIG_VENDOR_IMAGE_MAX_WIDTH
#define WINDOW_VENDOR_IMAGE_MAX_WIDTH	GKT_CONFIG_VENDOR_IMAGE_MAX_WIDTH
#else
#define WINDOW_VENDOR_IMAGE_MAX_WIDTH	GKT_SCREEN_WIDTH
#endif

#ifdef GKT_CONFIG_VENDOR_IMAGE_MAX_HEIGHT
#define WINDOW_VENDOR_IMAGE_MAX_HEIGHT	GKT_CONFIG_VENDOR_IMAGE_MAX_HEIGHT
#else
#define WINDOW_VENDOR_IMAGE_MAX_HEIGHT	32
#endif

#if (GKT_SCREEN_PF_MONOCHROME == GKT_SCREEN_PF)
#if (GKT_SCREEN_DMF_COL_ROW == GKT_SCREEN_DMF)
#define WINDOW_VENDOR_IMAGE_SIZE(width, height)	\
	(((width) * gkt_aligned(height, 8)) >> 3)
#else
#define WINDOW_VENDOR_IMAGE_SIZE(width, height)	\
	((gkt_aligned(width, 8) * height) >> 3)
#endif
#else

#if (GKT_SCREEN_PF_RGB565 == GKT_SCREEN_PF)
#if (GKT_SCREEN_DMF_COL_ROW == GKT_SCREEN_DMF)
#define WINDOW_VENDOR_IMAGE_SIZE(width, height)	\
	(((width) * gkt_aligned(height, 8)) >> 3)
#else
#define WINDOW_VENDOR_IMAGE_SIZE(width, height)	\
	((gkt_aligned(width, 8) * height) >> 3)
#endif
#endif
#endif



#define WINDOW_VENDOR_IMAGE_MAXSIZE	\
	WINDOW_VENDOR_IMAGE_SIZE(WINDOW_VENDOR_IMAGE_MAX_WIDTH, \
		WINDOW_VENDOR_IMAGE_MAX_HEIGHT)

/************************************************************
 * VENDOR IMAGE LAYOUT IN CARD SECTOR/BLOCK
 * SECTOR-01 :
 *   BLOCK-0 : vendor_image_header
 *   BLOCK-1 : vendor_image_data[00 ~ 15]
 *   BLOCK-2 : vendor_image_data[16 ~ 31]
 * SECTOR-02 :
 *   BLOCK-0 : vendor_image_data[32 ~ 47]
 *   BLOCK-1 : vendor_image_data[48 ~ 63]
 *   BLOCK-2 : vendor_image_data[64 ~ 79]
 * ... ... ...
 * SECTOR-0X :
 *   BLOCK-Y : vendor_image_data[N ~ N + 15]
 *************************************************************/
#define WINDOW_VENDOR_IMAGE_MAGIC	0x3D5D1E3C

typedef struct _window_vendor_image_header {
	uint32_t	magic;
	uint8_t	pixel_format;	/* pf = MONOCHROME, ... */
	uint8_t	dit_matrix_format;	/* dot matrix format = COL_ROW, ... */
	uint16_t	width;
	uint16_t	height;
	uint16_t	crc16;	/* data crc, CRC16_CCITT_FALSE, POLY = 0x1021, INIT = 0xFFFF */
	uint32_t	rfu;	/* reserved */
} window_vendor_image_header_s;

typedef struct _window_vendor_image {
	uint32_t	magic;
	uint16_t	width;
	uint16_t	height;
	uint8_t	data[WINDOW_VENDOR_IMAGE_MAXSIZE];
} window_vendor_image_s;

const window_vendor_image_s *window_vendor_get_image(void);

int window_vendor_update_image(gkt_rfid_info_s *rfid_info);

#else
#define WINDOW_VENDOR_IMAGE_ENABLE	0
#endif

#ifdef __cplusplus
}
#endif
 
#endif	/* WINDOW_VENDOR_H */

